package nl.nhl.idp.Components.Network;

import nl.nhl.idp.Components.Database.SensorData;

/**
 * Creates byte arrays for messages
 * @author Mark van der Wal
 *
 */
public class ProtocolEncoder 
{
	/**
	 * Encodes the turn message
	 * @param value for turn 0 - 255
	 * @return the byte array representing the message
	 */
	static public byte[] EncodeTurn(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.T_TURN.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
	
	/**
	 * Encodes the Drive message
	 * @param value
	 * @return
	 */
	static public byte[] EncodeDrive(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.T_DRIVE.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
	
	/**
	 * Encodes the command message
	 * @param value
	 * @return
	 */
	static public byte[] EncodeCommand(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.T_COMMAND.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
	
	/**
	 * Encodes the sensors message
	 * @param data
	 * @return
	 */
    static public byte[] EncodeSensors(SensorData data)
	{
		// create buffer
		byte[] buffer = new byte[7];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.V_SENSOR.Opcode();
		buffer[1] = (byte) data.getHellingshoek();
        buffer[2] = (byte) data.getAccuspanning();
        buffer[3] = (byte) data.getMotorspanning();
        buffer[4] = (byte) data.getMazeSensorLeft();
        buffer[5] = (byte) data.getMazeSensorForward();
        buffer[6] = (byte) data.getMazeSensorRight();
		
		return buffer;
	}
}
